﻿using CourseManagerment.Common;
using CourseManagerment.View;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace CourseManagerment.ViewModel
{
    public class MainViewModel : NotifyBase
    {
        public UserModel UserInfo { get; set; }
        private string _searchText;

        public string SearchText
        {
            get { return _searchText; }
            set { _searchText = value; this.DoNotify(); }
        }


        private FrameworkElement _mainContent;
        /// <summary>
        /// 主界面显示内容
        /// </summary>
        public FrameworkElement MainContent
        {
            get { return _mainContent; }
            set { _mainContent = value; this.DoNotify(); }
        }

        //命令部分
        public CommandBase NavChangedCommand { get; set; } = new() { DoCanExecute=e=>true};

        public MainViewModel()
        {
#if DEBUG
            UserInfo = new()
            {
                Avatar = "../Assets/Images/头像A.jpg",
                UserName = "管理员01",
                Gender = 1
            };
#else
            UserInfo = new();
#endif
            this.NavChangedCommand.DoExecute = DoNavChanged;

            //打开显示首页
            DoNavChanged(nameof(FirstPageView));
        }
        private void DoNavChanged(object obj)
        {
            //利用反射找到FirstPageView对象
            Type? type = Type.GetType("CourseManagerment.View." + obj.ToString());
            ConstructorInfo? cti = type?.GetConstructor(System.Type.EmptyTypes);
            this.MainContent = (FrameworkElement)cti!.Invoke(null);
        }
    }
}
